﻿$(function() {
    var chartRuKu = echarts.init(document.getElementById("chartRuKu"));
    var optionRuKu = {
        title: {
            text: '入库物资日结图表',
            subtext: '暂没有数据',
            x: 'center'
        },
        tooltip: {},
        legend: {
            data: ['入库物资日结图表'],
            show: false
        },
        xAxis: {
            data: [],
            axisLabel: { rotate: 15, interval: 0 }
        },
        yAxis: {},
        series: [{
            name: '入库物资日结图表',
            type: 'bar',
            barMaxWidth:70,
            data: [],
            label: { normal: { show: true, position: 'top'} }
}]
        };
        // 使用刚指定的配置项和数据显示图表。
        chartRuKu.setOption(optionRuKu);

        var chartChuKu = echarts.init(document.getElementById("chartChuKu"));
        var optionChuKu = {
            title: {
                text: '出库物资日结图表',
                subtext: "暂没有数据",
                x: 'center'
            },
            tooltip: {
                trigger: 'axis'
            },
            legend: {
                data: ['出库物资日结图表'],
                show: false
            },
            xAxis: {
                data: [],
                axisLabel: { rotate: 15, interval: 0 }
            },
            yAxis: {},
            series: [{
                name: '出库物资日结图表',
                type: 'bar',
                barMaxWidth:70,
                data: [],
                label: { normal: { show: true, position: 'top'} }
}]
            };
            // 使用刚指定的配置项和数据显示图表。
            chartChuKu.setOption(optionChuKu);


            var chartBanHeZhan = echarts.init(document.getElementById('chartBanHeZhan'));
            var optionBanHeZhan = {
                title: {
                    text: '拌合站实时生产数据',
                    subtext: "暂没有数据",
                    x: 'center'
                },
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b} : {c} ({d}%)"
                },
                legend: {
                    orient: 'vertical',
                    left: 'right',
                    data: []
                },
                series: [
                {
                    name: '拌合站消耗',
                    type: 'pie',
                    radius: '60%',
                    center: ['50%', '55%'],
                    data: [],
                    label: { normal: { show: true, position: 'outside', formatter: "{b}\n{c}吨\n{d}%"} },
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
            };

            chartBanHeZhan.setOption(optionBanHeZhan);
            var setChartIndex = function setIndexChart() {
                var zhanDian = $("#index-zhandian").combobox('getValue');
                if (!zhanDian) {
                    return;
                }
                chartRuKu.showLoading();
                chartChuKu.showLoading();
                chartBanHeZhan.showLoading();
                $.get('handler/indexchart.ashx', { "zhandian": zhanDian }, function(data, status) {
                    chartRuKu.hideLoading();
                    chartChuKu.hideLoading();
                    chartBanHeZhan.hideLoading();
                    var d = new Date();
                    chartRuKu.setOption({
                        title: {
                            subtext: '更新时间：' + d.toLocaleString()
                        },
                        tooltip: {
                            trigger: 'axis'
                        },
                        xAxis: {
                            data: data.categories_ruku
                        },
                        series: [{
                            // 根据名字对应到相应的系列
                            data: data.data_ruku}]
                        });
                        chartChuKu.setOption({
                            title: {
                                subtext: '更新时间：' + d.toLocaleString()
                            },
                            xAxis: {
                                data: data.categories_chuku
                            },
                            series: [{
                                // 根据名字对应到相应的系列
                                data: data.data_chuku}]
                            });
                            chartBanHeZhan.setOption({
                                title: { subtext: '更新时间：' + d.toLocaleString() },
                                legend: { data: data.categories_banhezhan },
                                series: [{ data: data.data_banhezhan}]
                            });

                        }, 'json');

                    }

                    $("#index-zhandian").combobox({
                        url: 'json/zhandian.json',
                        method: 'get',
                        valueField: 'zhandian',
                        textField: 'zhandian',
                        panelWidth: 150,
                        panelHeight: 'auto',
                        editable: false,
                        onLoadSuccess: function() {
                            setChartIndex();
                            setInterval(setChartIndex, 60000);
                        },
                        onSelect: function(record) {
                            setChartIndex();
                        }
                    });

                    $("#index-xiangmubu").combobox({
                        url: 'json/xiangmubu.json',
                        method: 'get',
                        valueField: 'xiangmubu',
                        textField: 'xiangmubu',
                        panelWidth: 300,
                        panelHeight: 'auto',
                        editable: false
                    });

                });